package opera;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:
 * Date: 2024-07-12
 * Time: 14:27
 */
public class AddOperation implements IOperation {
    @Override
    public void work(BookList bookList) {
        System.out.println("新增图书...");
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入新增图书名字：");
        String name = sc.nextLine();
        System.out.println("请输入新增图书作者：");
        String author = sc.nextLine();
        System.out.println("请输入新增图书类型：");
        String type = sc.nextLine();
        System.out.println("请输入新增图书价格：");
        int price = sc.nextInt();

        Book book = new Book(name,author,price,type);
        int currentSized = bookList.getUsedSized();
        for (int i = 0; i < currentSized; i++) {
            Book sss = bookList.getBook(i);
            if(sss.getName().equals(name)){
                System.out.println("已经有这本书了");
                return;
            }
        }
        bookList.setBooks(book);
        System.out.println("新添图书成功");
        bookList.setUsedSized(currentSized + 1);
    }
}
